//
//  ViewController.m
//  IconMaster
//
//  Created by mac on 2017/7/24.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "ViewController.h"
//#import "ImageLabelButton.h"
//#import "DBOperation.h"
#import "CImageUtil.h"
#import "CIconView.h"
#import "MongooseDaemon.h"
#import "RMStepsController.h"
#import "AlbumPhotoPicker.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *image0;
@property (nonatomic, strong) NSDictionary *inputDict;
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) CIconView* iconView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)cccc:(id)sender {
     UIImage *image2 = [UIImage imageNamed:@"skin_1"];
//    UIImage *image10 = [CImageUtil imageFromView:image2];
//    UIImage* iconImagett = [self.iconView iconImage];
//    UIImage *image1 = self.image0.image;
//    self.iconView = image10;
   
    self.inputDict = @{@"iconImage":image2,
                       @"title":@"大姐",
//                       @"iconView":image1,
                       @"value":@"https://itunes.apple.com/us/app/qq/id444934666?mt=8"};
    UIImage* iconImage = [self.inputDict objectForKey:@"iconImage"];
    SaveImageToDocument(iconImage, @"the_icon.png");
    NSString* title = [self.inputDict objectForKey:@"title"];
    NSString* value = [self.inputDict objectForKey:@"value"];
    
    [MongooseDaemon instance].composedUrl.title = title;
    [MongooseDaemon instance].composedUrl.password = nil;
    [MongooseDaemon instance].composedUrl.realUrl = value;
    
    NSString* urlString = [NSString stringWithFormat:@"http://localhost:8080/wei%ld",time(NULL)];
    NSLog(@"%@",urlString);
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{}   completionHandler:^(BOOL success) {
        if (success) {
            NSLog(@"Opened url");
        }
    }];
    [self.stepsController finishedAllSteps];
}
- (IBAction)photo:(id)sender {
    AlbumPhotoPicker* picker = [[AlbumPhotoPicker alloc] init];
    picker.controller = self;
    picker.allowsEditing = true;
    picker.finishBlock = ^(AlbumPhotoPicker* photoPicker, NSDictionary* infoDict) {
//        [self setIconImageWithPickerDict:infoDict];
        _image = [infoDict objectForKey:UIImagePickerControllerEditedImage];
        self.image0.image = _image;
        [self dismissViewControllerAnimated:YES completion:nil];
    };
    [picker pickAlbum];
}
- (IBAction)camera:(id)sender {
    AlbumPhotoPicker* picker = [[AlbumPhotoPicker alloc] init];
    picker.controller = self;
    picker.allowsEditing = true;
    picker.finishBlock = ^(AlbumPhotoPicker* photoPicker, NSDictionary* infoDict) {
//        [self setIconImageWithPickerDict:infoDict];
        _image = [infoDict objectForKey:UIImagePickerControllerEditedImage];
        self.image0.image = _image;
        [self dismissViewControllerAnimated:YES completion:nil];
    };
    [picker pickCamera];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
